package com.zhangsun.springRabbitMq.config;

import com.zhangsun.springRabbitMq.common.RabbitMqTopicConstant;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Topic模式消息队列
 */
@Configuration
public class RabbitMqTopicConfig {

    /**
     * 消息队列
     *
     * @return 消息队列
     */
    @Bean
    public Queue worldQueue1() {
        return new Queue(RabbitMqTopicConstant.TOPIC_HELLO_WORLD_1);
    }

    /**
     * 消息队列
     *
     * @return 消息队列
     */
    @Bean
    public Queue worldQueue2() {
        return new Queue(RabbitMqTopicConstant.TOPIC_HELLO_WORLD_2);
    }

    /**
     * Topic交换器
     *
     * @return Topic交换器
     */
    @Bean
    public TopicExchange helloExchange() {
        return new TopicExchange(RabbitMqTopicConstant.TOPIC_EXCHANGE_HELLO);
    }

    /**
     * 绑定交换器
     *
     * @return 绑定交换器
     */
    @Bean
    public Binding helloBinding1() {
        return BindingBuilder.bind(worldQueue1()).to(helloExchange()).with("lzc.message");
    }

    /**
     * 绑定交换器
     *
     * @return 绑定交换器
     */
    @Bean
    public Binding helloBinding2() {
        return BindingBuilder.bind(worldQueue2()).to(helloExchange()).with("lzc.message");
    }

}
